package com.zzh.ideas.web.framework.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * description: <br>
 * createTime: 2019/1/1010:14 <br>
 *
 * @author zzh
 */
@ControllerAdvice
public class GlobalExceptionController {
    private static Logger logger = LoggerFactory.getLogger(GlobalExceptionController.class);


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Map<String, Object> handleBusinessException(HttpServletRequest request, HttpServletResponse response, Exception e) {
        logger.error("发生异常: " + e.getMessage(), e);
        Map<String, Object> result = new HashMap<>();
        result.put("code", -1);
        result.put("msg", "异常");
        return result;
    }
}
